package com.wd.live.view;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.exoplayer2.C;
import com.wd.live.R;
import com.wd.live.base.BaseActivity;
import com.wd.live.base.BaseViewModel;
import com.wd.live.bean.MineMessageBean;
import com.wd.live.databinding.ActivityUserMessageBinding;
import com.wd.live.bean.SearchRzBean;
import com.wd.live.model.SpUtils;
import com.wd.live.view.activity.GaiNmaeActivity;
import com.wd.live.view.activity.GaiSexActivity;
import com.wd.live.viewmodel.UserMessageViewModel;

public class UserMessageActivity extends BaseActivity<UserMessageViewModel, ActivityUserMessageBinding> {


    private boolean status;
    private boolean ifBD=true;
    private String signature;
    private String nickName;
    private int sex;


    @Override
    protected void initData() {
        viewmodel.getList2().observe(UserMessageActivity.this, new Observer<MineMessageBean>() {
            @Override
            public void onChanged(MineMessageBean mineMessageBean) {
                MineMessageBean.ResultBean result = mineMessageBean.getResult();
                databind.userName2.setText(result.getNickName());
                Glide.with(UserMessageActivity.this)
                        .load(result.getPersonalImage())
                        .into(databind.userFM1);
                signature = result.getSignature();
                nickName = result.getNickName();
                sex = result.getSex();
                databind.userQian2.setText(signature);
                int bankCardBindingStatus = result.getBankCardBindingStatus();
                if(bankCardBindingStatus==2){
                    databind.yhkBD.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            startActivity(new Intent(UserMessageActivity.this,SeeBDActivity.class));
                        }
                    });
                }else {
                    databind.yhkBD.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            startActivity(new Intent(UserMessageActivity.this,BDbankcardActivity.class));
                        }
                    });
                }
            }
        });
        databind.backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        databind.QianMing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserMessageActivity.this, QianMingActivity.class);
                intent.putExtra("QM",signature);
                startActivity(intent);
            }
        });
        databind.userSMGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewmodel.getList().observe(UserMessageActivity.this, new Observer<SearchRzBean>() {
                    @Override
                    public void onChanged(SearchRzBean searchRzBean) {
                        status = searchRzBean.isStatus();
                        if(status){
                            startActivity(new Intent(UserMessageActivity.this,SussceRzActivity.class));
                            finish();
                        }else{
                            startActivity(new Intent(UserMessageActivity.this,UserSMActivity.class));
                            finish();
                        }
                    }
                });
            }
        });

        databind.userName3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UserMessageActivity.this, GaiNmaeActivity.class);
                intent.putExtra("nichengname",nickName);
                startActivity(intent);

            }
        });

        databind.userSex2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UserMessageActivity.this, GaiSexActivity.class);
                intent.putExtra("mysex",sex);
                startActivity(intent);
            }
        });
        databind.relXingzuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UserMessageActivity.this, GaiSexActivity.class);
                intent.putExtra("mysex",sex);
                startActivity(intent);
            }
        });
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_user_message;
    }

    @Override
    public void onChanged(Object o) {
 
    }

    @Override
    protected void onResume() {
        super.onResume();
        viewmodel.getList2().observe(UserMessageActivity.this, new Observer<MineMessageBean>() {
            @Override
            public void onChanged(MineMessageBean mineMessageBean) {
                MineMessageBean.ResultBean result = mineMessageBean.getResult();
                databind.userName2.setText(result.getNickName());
                Glide.with(UserMessageActivity.this)
                        .load(result.getPersonalImage())
                        .into(databind.userFM1);
                signature = result.getSignature();
                databind.userQian2.setText(signature);
                int bankCardBindingStatus = result.getBankCardBindingStatus();
                if(bankCardBindingStatus==2){
                    databind.yhkBD.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            startActivity(new Intent(UserMessageActivity.this,SeeBDActivity.class));
                        }
                    });
                }else {
                    databind.yhkBD.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            startActivity(new Intent(UserMessageActivity.this,BDbankcardActivity.class));
                        }
                    });
                }
            }
        });
    }
}